#ifndef REQUESTMAPPER_H
#define REQUESTMAPPER_H

#include "../httpserver/httprequesthandler.h"
#include "LoginHandler.h"
#include "myrequesthandler.h"

class RequestMapper : public HttpRequestHandler {
    Q_OBJECT
    Q_DISABLE_COPY(RequestMapper)
public:
    RequestMapper(QObject* parent = nullptr) : HttpRequestHandler(parent) {
        loginHandler = new LoginHandler(this);
        defaultHandler = new MyRequestHandler(this);
    }

    void service(HttpRequest& request, HttpResponse& response) override {
        QByteArray path = request.getPath();
        // 根据路径分发请求
        if (path == "/login") {
            loginHandler->service(request, response); // 登录请求交给LoginHandler
        } else {
            defaultHandler->service(request, response); // 其他请求用默认处理器
        }
    }

private:
    LoginHandler* loginHandler;
    MyRequestHandler* defaultHandler;
};

#endif // REQUESTMAPPER_H
